﻿// ===============================================================================
// XCI.WinForm.Platform 西安交通信息WinForm开发框架 2019 版权所有
// ===============================================================================

using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Registrator;
using DevExpress.XtraEditors.Repository;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using XCI.Core;
using XCI.Windows.Controls;

namespace XCI.Sys.Controls
{
    /// <summary>
    /// 状态下拉控件
    /// </summary>
    public class StatusComboBoxEdit: ComboBoxEditx
    {
        static StatusComboBoxEdit()
        {
            RepositoryItemStatusComboBoxEdit.RegisterStatusComboBoxEdit();
        }

        public StatusComboBoxEdit()
        {
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string ValueMember => "Id";
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string DisplayMember => "Name";

        /// <summary>
        /// True文本
        /// </summary>
        [DefaultValue("启用")]
        [Category("XCI")]
        [Description("True文本")]
        public virtual string TrueText { get; set; } = "启用";

        /// <summary>
        /// True值
        /// </summary>
        [DefaultValue("1")]
        [Category("XCI")]
        [Description("True值")]
        public virtual string TrueValue { get; set; } = "1";

        /// <summary>
        /// False文本
        /// </summary>
        [DefaultValue("禁用")]
        [Category("XCI")]
        [Description("False文本")]
        public virtual string FalseText { get; set; } = "禁用";

        /// <summary>
        /// False值
        /// </summary>
        [DefaultValue("0")]
        [Category("XCI")]
        [Description("False值")]
        public virtual string FalseValue { get; set; } = "0";

        /// <summary>
        /// 空文本
        /// </summary>
        [DefaultValue("全部状态")]
        [Category("XCI")]
        [Description("空文本")]
        public virtual string NullText { get; set; } = "全部状态";

        /// <summary>
        /// 空值
        /// </summary>
        [DefaultValue("")]
        [Category("XCI")]
        [Description("空值")]
        public virtual string NullValue { get; set; } = "";

        protected override void OnLoaded()
        {
            base.OnLoaded();
            if (DesignMode) return;
            Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
            DataSource = new List<Simple>
            {
                new Simple(NullValue,NullText),
                new Simple(TrueValue,TrueText),
                new Simple(FalseValue,FalseText)
            };
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public new RepositoryItemStatusComboBoxEdit Properties => base.Properties as RepositoryItemStatusComboBoxEdit;

        public override string EditorTypeName => RepositoryItemStatusComboBoxEdit.CustomEditName;
    }

    [UserRepositoryItem("RegisterStatusComboBoxEdit")]
    public class RepositoryItemStatusComboBoxEdit : RepositoryItemComboBoxEditx
    {
        static RepositoryItemStatusComboBoxEdit()
        {
            RegisterStatusComboBoxEdit();
        }

        public new const string CustomEditName = "StatusComboBoxEdit";

        public RepositoryItemStatusComboBoxEdit()
        {
        }

        public override string EditorTypeName => CustomEditName;

        public static void RegisterStatusComboBoxEdit()
        {
            Image img = null;
            EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(CustomEditName, typeof(StatusComboBoxEdit), typeof(RepositoryItemStatusComboBoxEdit), typeof(StatusComboBoxEditViewInfo), new StatusComboBoxEditPainter(), true, img));
        }

        public override void Assign(RepositoryItem item)
        {
            BeginUpdate();
            try
            {
                base.Assign(item);
                RepositoryItemStatusComboBoxEdit source = item as RepositoryItemStatusComboBoxEdit;
                if (source == null) return;
                //
            }
            finally
            {
                EndUpdate();
            }
        }
    }

    public class StatusComboBoxEditViewInfo : ComboBoxEditxViewInfo
    {
        public StatusComboBoxEditViewInfo(RepositoryItem item) : base(item)
        {
        }
    }

    public class StatusComboBoxEditPainter : ComboBoxEditxPainter
    {
        public StatusComboBoxEditPainter()
        {
        }
    }
}